/**
 * author:Administrator
 * date:2016/2/24
 * desc:TODO
 */
'use strict';


let seq = 1;
let list = {};

class WareRepoImpl {

  static * genId() {
    return 'order_' + (seq++);
  }

  static * find(id) {
    return list[id];
  }

  static * store(order) {
    if (!order.id) order.id = yield WareRepoImpl.genId();
    list[order.id] = order;
  }

  static * attachCoupon(id, couponLog, coupon, t) {
    let item = list[id];
    item.couponLogId = couponLog.id;
    item.money -= coupon.money;
    return true;
  }

  static * payOrder(id, t) {
    let item = list[id];
    if (item.status != 'notpay') return false;
    item.status = 'paid';
    return true;
  }
}
module.exports = WareRepoImpl;